/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2011-2012 www.pretty-tools.com
 */

var wwwPrettyTools_GooglePlusOneButtonConfiguration = {
    BRANCH: "extensions.prettytools.button.google.plus.one.",
    INSTALLED_PARAM: "installed.v1_1",
    SHARE_POPUP_PARAM: "share.popup"
};

wwwPrettyTools_GooglePlusOneButtonConfiguration.getBranch = function ()
{
    return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).QueryInterface(Components.interfaces.nsIPrefBranch).getBranch(this.BRANCH);
}

wwwPrettyTools_GooglePlusOneButtonConfiguration.isFirstStart = function ()
{
    try
    {
        var branch = this.getBranch();
        if (branch.prefHasUserValue(this.INSTALLED_PARAM))
            return false;

        branch.setBoolPref(this.INSTALLED_PARAM, true);
        return true;
    }
    catch(e)
    {
        dump("Exception during isFirstStart: " + ex + "\n");
        return false;
    }
}

wwwPrettyTools_GooglePlusOneButtonConfiguration.isOpenSharePopup = function ()
{
    try
    {
        var branch = this.getBranch();

        if (!branch.prefHasUserValue(this.SHARE_POPUP_PARAM))
            return true;// Open share popup by default

        return branch.getBoolPref(this.SHARE_POPUP_PARAM);
    }
    catch(e)
    {
        dump("Exception during isOpenSharePopup: " + ex + "\n");
        return false;
    }
}

wwwPrettyTools_GooglePlusOneButtonConfiguration.setOpenSharePopup = function (bOpenSharePopup)
{
    try
    {
        this.getBranch().setBoolPref(this.SHARE_POPUP_PARAM, bOpenSharePopup);
    }
    catch(e)
    {
        dump("Exception during setOpenSharePopup: " + ex + "\n");
    }
}

wwwPrettyTools_GooglePlusOneButtonConfiguration.onOptionsPageLoad = function ()
{
    try
    {
        document.getElementById("openSharePopup").checked = this.isOpenSharePopup();
    }
    catch(e)
    {
        dump("Exception during onOptionsPageLoad: " + ex + "\n");
    }
}

wwwPrettyTools_GooglePlusOneButtonConfiguration.onOptionsOK = function ()
{
    try
    {
        this.setOpenSharePopup(document.getElementById("openSharePopup").checked);
    }
    catch(e)
    {
        dump("Exception during onOptionsOK: " + ex + "\n");
    }
}
